const express = require('express');
const common = require('../../libs/common');
const mysql = require('mysql');

var db = mysql.createPool({
    host: 'localhost',
    user: 'root',
    password: 'mysql123456',
    database: '180618'
});

module.exports=function(){
    var router=express.Router();

    //检查登陆状态
    router.use((req, res, next)=>{
        if(!req.session['admin_id'] && req.url!='/login'){ //没有登录
            res.redirect('/admin/login');
        }else{
            next();
        }
    });

    //登录成功后页面跳转
    router.get('/',(req, res)=>{
        //res.send('恭喜您成功登录').end();
        res.render('admin/index.ejs',{});
    });

    router.use('/login',require('./login.js')());

    router.use('/banners',require('./banners.js')());

    router.use('/custom',require('./custom.js')());

    return router;
};